// pages/components/my-swiper.js
const {imagePrefix} = require('../../utils/commonUtil.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
      // 这里定义了属性，属性值可以在组件使用时指定
      bannerSource: {
          type: Array,
          value: [],
      }
  },

  /**
   * 组件的初始数据
   */
  data: {
      bannerSource:[],
      indicatorDots: false,
      autoplay: false,
      interval: 2000,
      duration: 500,
      previousMargin:'25rpx',
      swiperIndex:0,
      isSwiperTouching:false,
      imagePrefix,
      imgWidth:1080
  },

  lifetimes: {
      // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
      attached: function () {
          console.log('component my-swiper attached');
          console.log(this.data.bannerSource); // 页面参数的值
          this.setData({bannerSource:this.data.bannerSource});

          wx.getSystemInfo({
              success:obj=>{
                  //this.setData({imgWidth:Math.ceil(obj.screenWidth*700/750)*2});
              }
          })
      },
      moved: function () { },
      detached: function () { },
  },

  /**
   * 组件的方法列表
   */
  methods: {
      onLoad: function() {

      },
      swiperChange:function(e){
          console.log('swiper change');
          this.setData({
              swiperIndex: e.detail.current,
              isSwiperTouching:false
          })
      },
      onSwiperTouch:function(e){
          this.setData({isSwiperTouching:true},()=>{
              setTimeout(()=>{
                  this.setData({isSwiperTouching:false});
              },2000);
          })
      },
      goDeail:function (e) {
          let seed = e.currentTarget.dataset.id;
          let type = e.currentTarget.dataset.type;
          console.log({type,seed})
          if(type===1){
              wx.navigateTo({
                  url: "/pages/web/web?id="+encodeURIComponent(seed)
              });
          }else if(type===2){
              wx.navigateTo({
                  url: "/pages/exhibit-detail/detail?id="+seed
              });
          }
      }
  }
});
